package com.dailyblue.java.thread.四个方法;

import lombok.SneakyThrows;

// wait
public class DemoB {

    static class B1 implements Runnable {
        private B2 b2;

        public void setB2(B2 b2) {
            this.b2 = b2;
        }

        @Override
        public void run() {
            b2.b();
        }
    }

    static class B2 {
        @SneakyThrows
        public synchronized void b() {
            System.out.println(Thread.currentThread().getName() + "正在执行a方法！");
            // 超时时间过了
            // wait(2000);
            wait();
            System.out.println(Thread.currentThread().getName() + "继续执行a方法！");
        }
    }

    @SneakyThrows
    public static void main(String[] args) {
        B2 b = new B2();
        B1 b1 = new B1();
        B1 b2 = new B1();
        b1.setB2(b);
        new Thread(b1).start();
        new Thread(b2).start();
        b2.setB2(b);
        Thread.sleep(3000);
        synchronized (b){
            b.notifyAll();
        }
    }
}
